package com.yc.javaee.tomcat.impl;

import com.yc.javaee.tomcat.HttpServletRequest;
import com.yc.javaee.tomcat.HttpServletResponse;
import com.yc.javaee.tomcat.ServletException;

import javax.servlet.annotation.WebServlet;
import java.io.IOException;

/**
 * 1.继承, 2.重写, 3.配置
 * Servlet 生命周期: servlet对象默认在何时被创建出来?
 *  答: 默认在第一次访问时创建
 */
@WebServlet("/hello.s")
public class HelloServlet extends HttpServletImpl{
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        // 官方实现, 如果没有异常自动赋值200
        response.setStatus(200,"OK");
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().append("<h1>hello world!</h1>");
    }

    @Override
    public void init() {
        System.out.println("HelloServlet 初始化完成");
    }
}
